<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>林序3PG模型可视化系统-树种参数</title>
{#    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/css/bootstrap.min.css" rel="stylesheet">#}
{#    <link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-icons/1.11.1/font/bootstrap-icons.min.css" rel="stylesheet">#}
{#    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js"></script>#}
{#    <script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap/5.3.3/js/bootstrap.bundle.min.js"></script>#}

    <link href="{{ url_for('static',filename='bootstrap/css/bootstrap.min.css') }}" rel="stylesheet">
    <link href="{{ url_for('static',filename='bootstrap/bootstrap-icons-1.11.1/bootstrap-icons.min.css') }}" rel="stylesheet">
    <script src="{{ url_for('static',filename='jquery/jquery-3.7.1.min.js') }}"></script>
    <script src="{{ url_for('static',filename='bootstrap/js/bootstrap.bundle.min.js') }}"></script>
    <style>
        :root {
            --primary-color: #2E7D32;
            --secondary-color: #81C784;
            --accent-color: #DCEDC8;
            --text-color: #212121;
            --light-text: #757575;
            --light-green: #E8F5E9;
            --dark-green: #1B5E20;
            --amber: #FFD54F;
            --brown: #795548;
            --leaf-green: #66BB6A;
        }

        body {
            background-color: #F8F9FA;
            background-image: url("data:image/svg+xml,%3Csvg width='60' height='60' viewBox='0 0 60 60' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M54.627 0l.83.828-1.415 1.415L51.8 0h2.827zM5.373 0l-.83.828L5.96 2.243 8.2 0H5.374zM48.97 0l3.657 3.657-1.414 1.414L46.143 0h2.828zM11.03 0L7.372 3.657 8.787 5.07 13.857 0H11.03zm32.284 0L49.8 6.485 48.384 7.9l-7.9-7.9h2.83zM16.686 0L10.2 6.485 11.616 7.9l7.9-7.9h-2.83zm20.97 0l9.315 9.314-1.414 1.414L34.828 0h2.83zM22.344 0L13.03 9.314l1.414 1.414L25.172 0h-2.83zM32 0l12.142 12.142-1.414 1.414L30 .828 17.272 13.556l-1.414-1.414L28 0h4zM.284 0l28 28-1.414 1.414L0 2.544V0h.284zM0 5.373l25.456 25.455-1.414 1.415L0 8.2V5.374zm0 5.656l22.627 22.627-1.414 1.414L0 13.86v-2.83zm0 5.656l19.8 19.8-1.415 1.413L0 19.514v-2.83zm0 5.657l16.97 16.97-1.414 1.415L0 25.172v-2.83zM0 28l14.142 14.142-1.414 1.414L0 30.828V28zm0 5.657L11.314 44.97 9.9 46.386l-9.9-9.9v-2.828zm0 5.657L8.485 47.8 7.07 49.212 0 42.143v-2.83zm0 5.657l5.657 5.657-1.414 1.415L0 47.8v-2.83zm0 5.657l2.828 2.83-1.414 1.413L0 53.456v-2.83zM54.627 60L30 35.373 5.373 60H8.2L30 38.2 51.8 60h2.827zm-5.656 0L30 41.03 11.03 60h2.828L30 43.858 46.142 60h2.83zm-5.656 0L30 46.686 16.686 60h2.83L30 49.515 40.485 60h2.83zm-5.657 0L30 52.343 22.344 60h2.83L30 55.172 34.828 60h2.83zM32 60l-2-2-2 2h4zM59.716 0l-28 28 1.414 1.414L60 2.544V0h-.284zM60 5.373L34.544 30.828l1.414 1.415L60 8.2V5.374zm0 5.656L37.373 33.656l1.414 1.414L60 13.86v-2.83zm0 5.656l-19.8 19.8 1.415 1.413L60 19.514v-2.83zm0 5.657l-16.97 16.97 1.414 1.415L60 25.172v-2.83zM60 28L45.858 42.142l1.414 1.414L60 30.828V28zm0 5.657L48.686 44.97l1.415 1.415 9.9-9.9v-2.828zm0 5.657L51.515 47.8l1.414 1.414L60 42.143v-2.83zm0 5.657l-5.657 5.657 1.414 1.415L60 47.8v-2.83zm0 5.657l-2.828 2.83 1.414 1.413L60 53.456v-2.83zM39.9 16.385l1.414-1.414L30 3.658 18.686 14.97l1.415 1.415 9.9-9.9 9.9 9.9zm-2.83 2.828l1.415-1.414L30 9.313 21.515 17.8l1.414 1.413L30 11.8l7.07 7.414v-.002zm-2.827 2.83l1.414-1.416L30 14.97l-5.657 5.657 1.414 1.415L30 17.8l4.243 4.242zm-2.83 2.827l1.415-1.414L30 20.626l-2.828 2.83 1.414 1.414L30 23.456l1.414 1.414zM56.87 59.414L58.284 58 30 29.716 1.716 58l1.414 1.414L30 32.544l26.87 26.87z' fill='%2381c784' fill-opacity='0.07' fill-rule='evenodd'/%3E%3C/svg%3E");
            color: var(--text-color);
            padding: 2rem;
            min-height: 100vh;
        }

        .page-header {
            margin-bottom: 2.5rem;
            display: flex;
            justify-content: space-between;
            align-items: center;
            padding-bottom: 1.2rem;
            border-bottom: 1px solid rgba(0, 0, 0, 0.07);
        }

        .page-title {
            color: var(--primary-color);
            font-weight: 700;
            font-size: 2rem;
            margin-bottom: 0;
            position: relative;
            padding-left: 2.2rem;
        }

        .page-title::before {
            content: "";
            position: absolute;
            left: 0;
            top: 50%;
            transform: translateY(-50%);
            width: 1.8rem;
            height: 1.8rem;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' width='24' height='24'%3E%3Cpath fill='none' d='M0 0h24v24H0z'/%3E%3Cpath d='M12.9 6.858l4.242 4.243L7.242 21H3v-4.243l9.9-9.9zm1.414-1.414l2.121-2.122a1 1 0 0 1 1.414 0l2.829 2.829a1 1 0 0 1 0 1.414l-2.122 2.121-4.242-4.242z' fill='%232E7D32'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-size: contain;
        }

        .btn-add-tree {
            background-color: var(--primary-color);
            border-color: var(--primary-color);
            padding: 0.6rem 1.2rem;
            border-radius: 8px;
            font-weight: 500;
            box-shadow: 0 2px 8px rgba(46, 125, 50, 0.3);
            transition: all 0.3s ease;
        }

        .btn-add-tree:hover {
            background-color: var(--dark-green);
            border-color: var(--dark-green);
            box-shadow: 0 4px 12px rgba(46, 125, 50, 0.4);
            transform: translateY(-2px);
        }

        .tree-card {
            transition: all 0.3s ease;
            border: none;
            border-radius: 12px;
            margin-bottom: 1.5rem;
            cursor: pointer;
            position: relative;
            background: white;
            box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
            overflow: hidden;
        }

        .tree-card::before {
            content: "";
            position: absolute;
            top: 0;
            left: 0;
            width: 100%;
            height: 6px;
            background: linear-gradient(90deg, var(--leaf-green), var(--secondary-color));
        }

        .tree-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
        }

        .tree-card:hover::before {
            background: linear-gradient(90deg, var(--dark-green), var(--primary-color));
        }

        .tree-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 0.8rem;
            padding-bottom: 0.8rem;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
        }

        .tree-title {
            font-weight: 600;
            color: var(--primary-color);
            margin-bottom: 0;
            font-size: 1.25rem;
            white-space: nowrap;
            overflow: hidden;
            text-overflow: ellipsis;
            max-width: 80%;
            display: flex;
            align-items: center;
        }

        .tree-title i {
            margin-right: 0.5rem;
            color: var(--leaf-green);
            font-size: 1.35rem;
        }

        .tree-icon {
            display: inline-block;
            width: 22px;
            height: 22px;
            margin-right: 8px;
            background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M12.5 2a7.5 7.5 0 0 1 5.645 12.438L25 21.293 23.59 22.71l-6.86-6.855A7.5 7.5 0 1 1 12.5 2zm0 2a5.5 5.5 0 1 0 0 11 5.5 5.5 0 0 0 0-11z' fill='%2366BB6A'/%3E%3C/svg%3E");
            background-repeat: no-repeat;
            background-size: contain;
        }

        .tree-info {
            display: flex;
            flex-wrap: wrap;
            color: var(--light-text);
            font-size: 0.9rem;
            margin-top: 0.5rem;
        }

        .tree-info-item {
            margin-right: 1.5rem;
            margin-bottom: 0.5rem;
            display: flex;
            align-items: center;
            padding: 0.3rem 0.6rem;
            border-radius: 6px;
            font-size: 0.85rem;
        }

        .tree-info-item.id {
            background-color: #E8F5E9;
            color: var(--primary-color);
        }

        .tree-info-item.time {
            background-color: #FFF8E1;
            color: #F57F17;
        }

        .tree-info-item i {
            margin-right: 0.4rem;
            font-size: 0.95rem;
        }

        .tree-actions {
            display: flex;
            gap: 0.5rem;
        }

        .btn-action {
            padding: 0.35rem 0.6rem;
            font-size: 0.875rem;
            border-radius: 8px;
            transition: all 0.2s ease;
        }

        .btn-edit-tree {
            color: #0288D1;
            border-color: rgba(2, 136, 209, 0.2);
            background-color: rgba(2, 136, 209, 0.05);
        }

        .btn-edit-tree:hover {
            background-color: rgba(2, 136, 209, 0.15);
            border-color: rgba(2, 136, 209, 0.3);
            color: #01579B;
        }

        .btn-delete-tree {
            color: #e53935;
            border-color: rgba(229, 57, 53, 0.2);
            background-color: rgba(229, 57, 53, 0.05);
        }

        .btn-delete-tree:hover {
            background-color: rgba(229, 57, 53, 0.15);
            border-color: rgba(229, 57, 53, 0.3);
            color: #c62828;
        }

        .tree-card-footer {
            background-color: var(--light-green);
            border-top: none;
            padding: 0.7rem 1.25rem;
            font-size: 0.85rem;
            color: var(--dark-green);
            display: flex;
            align-items: center;
        }

        .tree-type-badge {
            display: inline-block;
            padding: 0.25rem 0.5rem;
            border-radius: 4px;
            font-size: 0.8rem;
            font-weight: 500;
            margin-left: auto;
        }

        .tree-type-badge.conifer {
            background-color: #E8F5E9;
            color: var(--dark-green);
        }

        .tree-type-badge.broadleaf {
            background-color: #DCEDC8;
            color: #33691E;
        }

        .tree-type-badge.bamboo {
            background-color: #F1F8E9;
            color: #558B2F;
        }

        .empty-state {
            text-align: center;
            padding: 4rem 1rem;
            color: var(--light-text);
            background-color: white;
            border-radius: 12px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            margin-top: 2rem;
        }

        .empty-state i {
            font-size: 4rem;
            margin-bottom: 1.2rem;
            color: var(--secondary-color);
            opacity: 0.7;
            display: block;
        }

        .empty-state h4 {
            color: var(--primary-color);
            font-weight: 600;
            margin-bottom: 1rem;
        }

        .empty-state p {
            color: var(--light-text);
            max-width: 300px;
            margin: 0 auto;
        }

        /* 模态窗口样式 */
        .modal-content {
            border-radius: 12px;
            border: none;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.15);
            overflow: hidden;
        }

        .modal-header {
            background: linear-gradient(135deg, #2E7D32, #388E3C);
            color: white;
            padding: 1.2rem 1.5rem;
            border-bottom: none;
        }

        .modal-header .btn-close {
            color: white;
            box-shadow: none;
            opacity: 0.8;
            transition: opacity 0.2s ease;
        }

        .modal-header .btn-close:hover {
            opacity: 1;
        }

        .modal-body {
            padding: 1.8rem;
        }

        .modal-footer {
            border-top: 1px solid rgba(0, 0, 0, 0.05);
            padding: 1rem 1.5rem;
        }

        .form-label {
            font-weight: 500;
            color: var(--primary-color);
            margin-bottom: 0.5rem;
        }

        .form-control, .form-select {
            padding: 0.6rem 0.8rem;
            border-radius: 8px;
            border: 1px solid rgba(0, 0, 0, 0.1);
            transition: all 0.3s ease;
        }

        .form-control:focus, .form-select:focus {
            border-color: var(--secondary-color);
            box-shadow: 0 0 0 3px rgba(129, 199, 132, 0.25);
        }

        .parameter-preview {
            background-color: var(--light-green);
            border-radius: 8px;
            padding: 1rem;
            margin-top: 1rem;
        }

        .parameter-preview h6 {
            color: var(--primary-color);
            margin-bottom: 0.8rem;
            font-weight: 600;
        }

        .parameter-item {
            display: flex;
            justify-content: space-between;
            margin-bottom: 0.5rem;
            font-size: 0.9rem;
        }

        .parameter-name {
            color: var(--dark-green);
            font-weight: 500;
        }

        .parameter-value {
            color: var(--light-text);
        }

        /* 删除确认样式 */
        .delete-alert {
            color: #721c24;
            background-color: #f8d7da;
            border-color: #f5c6cb;
            font-weight: 500;
            margin-bottom: 1rem;
            padding: 0.75rem 1.25rem;
            border-radius: 0.25rem;
        }

        .tree-parameters {
            margin-top: 1.2rem;
            padding-top: 1rem;
            border-top: 1px dashed rgba(0, 0, 0, 0.1);
        }

        .parameters-title {
            color: var(--primary-color);
            font-size: 0.95rem;
            font-weight: 600;
            margin-bottom: 0.8rem;
            display: flex;
            align-items: center;
        }

        .parameters-title::before {
            font-family: "bootstrap-icons";
            margin-right: 0.5rem;
            font-size: 1.1rem;
        }

        .parameter-grid {
            display: grid;
            grid-template-columns: repeat(2, 1fr);
            gap: 0.8rem;
        }

        .parameter-item {
            background-color: #f8f9fa;
            border-radius: 6px;
            padding: 0.5rem 0.8rem;
            font-size: 0.85rem;
        }

        .parameter-name {
            color: var(--light-text);
            margin-bottom: 0.2rem;
            font-size: 0.75rem;
        }

        .parameter-value {
            color: var(--dark-green);
            font-weight: 500;
        }
    </style>
</head>
<body>
    <div class="container-fluid p-0">
        <!-- 页面标题和添加树种按钮 -->
        <div class="page-header">
            <h1 class="page-title">树种参数</h1>
            <button type="button" class="btn btn-primary btn-add-tree" data-bs-toggle="modal" data-bs-target="#newTreeModal">
                <i class="bi bi-plus-lg"></i> 添加树种参数
            </button>
        </div>

        <!-- 树种参数列表卡片 -->
        <div class="row" id="treeList">
            {% for specie in species %}
            <div class="col-12 col-md-6 col-xl-3 mb-3">
                <div class="card tree-card" data-tree-id="1">
                    <div class="card-body">
                        <div class="tree-header">
                            <h5 class="tree-title" title="">
                                <i class="bi bi-tree"></i>{{ specie.speciesname }}
                            </h5>
                            <div class="tree-actions">
                                <button class="btn btn-action btn-edit-tree" title="编辑参数" onclick="window.location.href='{{ url_for('func.editspecies', speciesId=specie.id) }}' ">
                                    <i class="bi bi-pencil"></i>
                                </button>
                                <button class="btn btn-action btn-delete-tree" data-tree-id="{{ specie.id }}" data-tree-name="{{ specie.speciesname }}" data-tree-create="{{ specie.create_time }}" title="删除树种">
                                    <i class="bi bi-trash"></i>
                                </button>
                            </div>
                        </div>
                        <div class="tree-info">
                            <div class="tree-info-item id">
                                <i class="bi bi-hash"></i>
                                <span>{{ specie.id }}</span>
                            </div>
                            <div class="tree-info-item time">
                                <i class="bi bi-clock-history"></i>
                                <span>{{ specie.create_time }}</span>
                            </div>
                        </div>

                        <!-- 新增的树种参数区域 -->
                        <div class="tree-parameters">
                            <span class="parameters-title"><i class="bi bi-graph-up"></i>&nbsp;&nbsp;部分参数预览</span>
                            <div class="parameter-grid">
                                <div class="parameter-item">
                                    <div class="parameter-name">Topt</div>
                                    <div class="parameter-value">{{ specie.Topt }}</div>
                                </div>
                                <div class="parameter-item">
                                    <div class="parameter-name">alpha</div>
                                    <div class="parameter-value">{{ specie.alpha }}</div>
                                </div>
                                <div class="parameter-item">
                                    <div class="parameter-name">pFS20</div>
                                    <div class="parameter-value">{{ specie.pFS20 }}</div>
                                </div>
                                <div class="parameter-item">
                                    <div class="parameter-name">SWconst</div>
                                    <div class="parameter-value">{{ specie.SWconst }}</div>
                                </div>
                            </div>
                        </div>

                    </div>
                    <div class="card-footer tree-card-footer"></div>
                </div>
            </div>
            {% endfor %}
        </div>

        <!-- 空状态提示 -->
        {% if projects|length < 1 %}
        <div class="empty-state d-none" id="emptyState">
            <i class="bi bi-tree"></i>
            <h4>暂无可用的树种参数</h4>
            <p>点击"添加树种参数"按钮添加一个树种</p>
        </div>
        {% endif %}
    </div>

    <!-- 添加树种参数模态窗口 -->
    <div class="modal fade" id="newTreeModal" tabindex="-1" aria-labelledby="newTreeModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="newTreeModalLabel">添加树种参数</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="alert alert-info d-flex align-items-center mb-4">
                        <i class="bi bi-info-circle-fill me-2"></i>
                        <div>提示：输入树种名称后系统将创建默认参数模板，您可以在编辑页面中修改具体参数值</div>
                    </div>

                    <form id="newTreeForm" action="{{ url_for('func.addspecies') }}" method="post">
                        <div class="mb-3">
                            <label for="treeName" class="form-label">树种名称</label>
                            <input name="speciesname" type="text" class="form-control" id="treeName" placeholder="请输入树种名称" required>
                        </div>
                        <div class="modal-footer">
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                            <button type="submit" class="btn btn-primary">保存</button>
                        </div>
                    </form>
                </div>

            </div>
        </div>
    </div>

    <!-- 删除树种确认模态窗口 -->
    <div class="modal fade" id="deleteTreeModal" tabindex="-1" aria-labelledby="deleteTreeModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="deleteTreeModalLabel">删除树种参数</h5>
                    <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
                </div>
                <div class="modal-body">
                    <div class="delete-alert">
                        <i class="bi bi-exclamation-triangle"></i> 警告：确定要永久删除此树种吗？此操作不可恢复
                    </div>
                    <form id="deleteSpeciesForm" action="{{ url_for('func.deletespecies') }}" method="post">
                        <div class="mb-3">
                            <label for="speciesId" class="form-label">树种唯一标识码</label>
                            <input name="deletespeciesid" type="text" class="form-control" id="speciesId" readonly>
                        </div>
                        <div class="mb-3">
                            <label for="speciesName" class="form-label">树种名称</label>
                            <input name="deletespeciesname" type="text" class="form-control" id="deletespeciesName" readonly>
                        </div>
                        <div class="mb-3">
                            <label for="speciesName" class="form-label">最近修改时间</label>
                            <input name="deletespeciescreatetime" type="text" class="form-control" id="speciesCreateTime" readonly>
                        </div>
                        <div class="modal-footer">
                            <!-- 取消按钮 -->
                            <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                            <!-- 提交按钮 -->
                            <button type="submit" class="btn btn-danger">提交</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>

    <!-- 脚本部分已省略 -->
    <script>

        $(document).ready(function() {
            renderTrees()
        });

        // 渲染树种列表函数
        function renderTrees() {
            // 点击删除按钮事件
            $(".btn-delete-tree").click(function(e) {
                const treeId = $(this).data("tree-id");
                const treeName = $(this).data("tree-name");
                const treeCreate = $(this).data("tree-create");

                // 设置当前要删除的树种ID和名称
                currentDeleteTreeId = treeId;

                // 打开删除确认模态窗口
                $("#deleteTreeModal").modal("show");
                $("#speciesId").val(treeId);
                $("#deletespeciesName").val(treeName);
                $("#speciesCreateTime").val(treeCreate);

            });
        }
    </script>
</body>
</html>